<x-layout>

  <div class="container b542">
    <div class="row mt-4">
      <div class="col">
        <div class="control-bg cd7a93c text-center p-3 fw-light ">
          <div class="row">
            <div class="col text-start">开源情况</div>
            <div class="col text-end">已开源</div>
          </div>
          <div class="row my-1">
            <div class="col text-start">总发行量</div>
            <div class="col text-end">21000000 MGCC</div>
          </div>
          <div class="row ">
            <div class="col text-start">持币地址</div>
            <div class="col text-end" id="taddr">5678909871</div>
          </div>
        </div>
      </div>
    </div>

    <div class="row mt-3">
      <div class="col">
        <div class="control-bg cd7a93c text-center p-3 ">
          <div class="row">
            <div class="col">矿池剩余总量</div>
          </div>
          <div class="row mt-2">
            <div class="col fs-6 " id="t001"></div>
          </div>
        </div>
      </div>
    </div>

    <div class="row mt-3">
      <div class="col">
        <div class="clearfix cd7a93c text-center">
          <div class="bgcol6 p-2 w-48 float-start">
            <div class="row">
              <div class="col fs-6  fw-light">销毁地址/MGCC</div>
            </div>
            <div class="row">
              <div class="col fs-6 " id="t002"></div>
            </div>
          </div>
          <div class="bgcol6 p-2 w-48 float-end ">
            <div class="row">
              <div class="col fs-6  fw-light">流通量/MGCC</div>
            </div>
            <div class="row">
              <div class="col fs-6 " id="t003"></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="row mt-3">
      <div class="col">
        <div class="clearfix cd7a93c text-center  ">
          <div class="bgcol6 p-2 w-48 float-start">
            <div class="row">
              <div class="col fs-6  fw-light">TRX-MGCC $</div>
            </div>
            <div class="row">
              <div class="col fs-6 " id="t004"></div>
            </div>
          </div>
          <div class="bgcol6 p-2 w-48 float-end ">
            <div class="row">
              <div class="col fs-6  fw-light">24小时成交额$</div>
            </div>
            <div class="row">
              <div class="col fs-6 " id="t005"></div>
            </div>
          </div>
        </div>
      </div>

    </div>

    <div class="row mt-3">
      <div class="col">
        <div class="clearfix  text-center  ">
          <button class="bgbtn p-2 w-48 float-start" type="button" id="jiedian1">
            节点排名
          </button>
          <button class="bgbtn p-2 w-48 float-end  btn-disabled" type="button" id="jiedian2">
            超级节点
          </button>
        </div>
      </div>

    </div>


    <div class="row mt-3">
      <div class="col">
        <table class="table table-borderless text-center">
          <thead class="text-white  ">
            <th class="fw-light">排名</th>
            <th class="fw-light">小区业绩</th>
            <th class="fw-light">地址</th>
          </thead>
          <tbody id="box">

            <!-- <tr class="text-secondary">
              <td>
                <img src="./img1/top1.png" alt="">
              </td>
              <td>1123312312.3122313</td>
              <td>dcasd***dsa56</td>
            </tr>
            <tr class="text-secondary">
              <td>
                <img src="./img1/top2.png" alt="">
              </td>
              <td>1123312312.3122313</td>
              <td>dcasd***dsa56</td>
            </tr>
            <tr class="text-secondary">
              <td>
                <img src="./img1/top3.png" alt="">
              </td>
              <td>1123312312.3122313</td>
              <td>dcasd***dsa56</td>
            </tr>
            <tr class="text-secondary">
              <td>
                4
              </td>
              <td>1123312312.3122313</td>
              <td>dcasd***dsa56</td>
            </tr>
            <tr class="text-secondary">
              <td>
                5
              </td>
              <td>1123312312.3122313</td>
              <td>dcasd***dsa56</td>
            </tr> -->
          </tbody>

        </table>
      </div>
    </div>



    <!-- tailwindcss -->

  </div>

</x-layout>



<script>




  var page = 1;
  var type = 1; //1：节点 2：超级节点

  function fetchNext(token, page, type) {
    axios.post(mgRoute.rank, {
      "current": page || 1,
      "size": 10,
      "type": type
    }, {
      headers: {
        token: token
      }
    }).then((r) => {
      var d = r.data
      if (d.status == 200) {
        j = d.data
        if (j.length > 0) {
          page++;

          var line = '';
          var len = j.length;
          for (i = 0; i < len; i++) {

            var r = j[i].sort;

            if(i <=2){
              var t= i+1;
              r = '<img src="./img1/top'+ t +'.png" alt="">';
            }

            var jiaddr = parseStringToStar(j[i].address)



            line += '<tr class="text-secondary">'
            +'<td>' +r + '</td>'
            +'<td>' + j[i].minPerformance + '</td>'
            +'<td>' + jiaddr + '</td></tr>'
          }

          if (line) {
            $("#box").append(line);
          }
        }

      } else {
        alert("请求失败")
      }
    }).catch((e) => {
      alert(e.message)
    })

  }


  $(function() {

    token = mgToken()
    user = mgUser()

    // dlog(user)

    // $("#taddr").text(user.address)

    axios.post(mgRoute.coinInfo, {}, {
      headers: {
        token: token
      }
    }).then((r) => {
      var d = r.data
      if (d.status == 200) {
        j = d.data
        // setTimeout(function(){

        //   dlog(j)
        // },1000)
        $("#t001").text(j.miningPoolRemainingNumber)
        $("#t002").text(j.quantityDestroyed)
        $("#t003").text(j.circulation)
        $("#t004").text(j.trx_mgcc)
        $("#t005").text(j.tradingVolume)
      } else {
        alert("请求失败")
      }
    }).catch((e) => {
      dlog(e)
    })


    fetchNext(token, page,type);


    $("#jiedian1").on("click", function() {
      $("#box").empty()
      page = 1
      type = 1;
      $('#jiedian2').addClass("btn-disabled");
      $(this).removeClass("btn-disabled");
      fetchNext(token, page, type);
    })

    $("#jiedian2").on("click", function() {
      $("#box").empty()
      page = 1
      type = 2;
      $('#jiedian1').addClass("btn-disabled");
      $(this).removeClass("btn-disabled");
      fetchNext(token, page, type);
    })

  })
</script>